package com.huaxia.controller.newAdd;


import com.huaxia.pojo.newAdd.BranchNewAdd;
import com.huaxia.pojo.newAdd.SaleDeptNewAdd;
import com.huaxia.service.newAdd.NewAddService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.context.WebApplicationContext;

import javax.servlet.ServletContext;
import java.util.List;

/**
 * @author wangli 爱我华夏，爱我中华！
 * @date 2020/06/08 11:35
 */

@RestController
@RequestMapping("/newAdd")
public class NewAddController {

    @Autowired
    private WebApplicationContext webApplicationContext;
    @Autowired
    private NewAddService newAddService;

    //新增
    @GetMapping("/getBranchNewAdd")
    public List<BranchNewAdd> getBranchNewAdd(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<BranchNewAdd> branchNewAdds = (List<BranchNewAdd>) servletContext.getAttribute("branchNewAdds");
        if(branchNewAdds==null){
            branchNewAdds = newAddService.getBranchNewAdd();
            servletContext.setAttribute("branchNewAdds",branchNewAdds);
            return branchNewAdds;
        }
        return branchNewAdds;
    }


    @GetMapping("/getSaleDeptNewAdd")
    public List<SaleDeptNewAdd> getSaleDeptNewAdd(){
        ServletContext servletContext = webApplicationContext.getServletContext();
        List<SaleDeptNewAdd> saleDeptNewAdds = (List<SaleDeptNewAdd>) servletContext.getAttribute("saleDeptNewAdds");
        if(saleDeptNewAdds==null){
            saleDeptNewAdds = newAddService.getSaleDeptNewAdd();
            servletContext.setAttribute("saleDeptNewAdds",saleDeptNewAdds);
            return saleDeptNewAdds;
        }
        return saleDeptNewAdds;
    }


}
